package 算法.练习;

/**
 * @author:谢君臣
 * @Date:2021/6/22-11:13
 * @version:1.0
 * @function:
 */
public class SingleTone {

    private static SingleTone instance = null;
    public SingleTone() {
        System.out.println(Thread.currentThread().getName()+"调用了无参构造器");
    }
    public static SingleTone getInstance() {
        if(instance==null){
            synchronized (SingleTone.class){
            if (instance==null)
                instance = new SingleTone();
        }
    }
        return instance;
    }
    public static void test(){
        System.out.println("123");
    }
    public static void main(String[] args) {

        for (int i = 0; i < 1000; i++) {
            new Thread(()->{
                SingleTone instance = SingleTone.getInstance();
                instance.test();
            }).start();
        }
    }
}
